//
//  MyViewController.m
//  Hai
//
//  Created by 千金贷 on 16/2/23.
//  Copyright © 2016年 wangzijian. All rights reserved.
//

#import "BMCalendarViewController.h"
#import "SJAvatarBrowser.h"
#import "UIImageView+WebCache.h"
#import "ChildCell.h"
#import "HeightPickViewController.h"
@interface BMCalendarViewController ()

@end

@implementation BMCalendarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"日历";
    UIBarButtonItem *todayItem = [[UIBarButtonItem alloc] initWithTitle:@"今天" style:UIBarButtonItemStylePlain target:self action:@selector(todayItemClicked:)];
    todayItem.tintColor=WhiteColor;
    [todayItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14],NSFontAttributeName, nil] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = todayItem;
    self.navigationItem.leftBarButtonItem=nil;
    [self.collectionView registerClass:[ChildCell class] forCellWithReuseIdentifier:@"ChildCell"];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _calendar.dataSource = self;
    _calendar.delegate = self;
    [_calendar reloadData];
    _calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase|FSCalendarCaseOptionsWeekdayUsesUpperCase;
    _calendar.backgroundColor = [UIColor whiteColor];
    
    JTMaterialSwitch *hsStartSwitch = [[JTMaterialSwitch alloc] initWithSize:JTMaterialSwitchSizeNormal
                                                                           style:JTMaterialSwitchStyleDefault
                                                                           state:JTMaterialSwitchStateOn];
    hsStartSwitch.tag=104;
    hsStartSwitch.center = CGPointMake(kScreenWidth-40, 280);
    [hsStartSwitch addTarget:self action:@selector(stateChanged:) forControlEvents:UIControlEventValueChanged];
    [self.bottomView addSubview:hsStartSwitch];
    JTMaterialSwitch *sgSwitch = [[JTMaterialSwitch alloc] initWithSize:JTMaterialSwitchSizeNormal
                                                                           style:JTMaterialSwitchStyleDefault
                                                                           state:JTMaterialSwitchStateOn];
    sgSwitch.tag=105;
    sgSwitch.center = CGPointMake(kScreenWidth-40, 331);
    [sgSwitch addTarget:self action:@selector(stateChanged:) forControlEvents:UIControlEventValueChanged];
    [self.bottomView addSubview:sgSwitch];

     [self initDate];
}
- (void)initDate
{
    _childArray = [[NSMutableArray alloc]init];
    [_childArray addObject:@{@"text":@"一孩",@"flag":@"1"}];
    [_childArray addObject:@{@"text":@"二孩",@"flag":@"0"}];
    
}
- (IBAction)height{
    HeightPickViewController *pickVC = [[HeightPickViewController alloc]init];
    [self addChildViewController:pickVC];
    pickVC.heightDataDelegate = self;
    pickVC.view.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight-64-49);
   [self.view addSubview:pickVC.view];
    
 

}
- (void)sendHeightData:(NSString * __nullable)data1 dataIndex1:(NSString * __nullable)dataIndex1 data2:(NSString * __nullable)data2 detaIndex2:(NSString * __nullable)dataIndex2{
    NSLog(@"%@~%@~%@~%@",data1,dataIndex1,data2,dataIndex2);
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewDidAppear:animated];
     self.navigationController.navigationBarHidden =NO;
} 
-(void)stateChanged:(id)sender{
    JTMaterialSwitch *switchButton = (JTMaterialSwitch*)sender;
   // switchButton.isOn
   // getSwitchState
    NSLog(@"%hhd",switchButton.isOn);
       NSLog(@"%hhd",switchButton.getSwitchState);
} 


- (void)dealloc
{
    NSLog(@"%s",__FUNCTION__);
}

- (void)todayItemClicked:(id)sender
{
    [_calendar setCurrentPage:[NSDate date] animated:YES];
    [self.calendar selectDate:[NSDate date]];
}

#pragma mark - <FSCalendarDelegate>

- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
    
    NSLog(@"%s 111111%@", __FUNCTION__, [calendar stringFromDate:date format:@"yyyy/MM/dd"]);
}

- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
{
    NSLog(@"%s %@", __FUNCTION__, [calendar stringFromDate:calendar.currentPage format:@"MMMM yyyy dd"]);
}
//定义每个UICollectionView 的 margin
//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    return UIEdgeInsetsMake(15, 10, 0, 0);
//}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.childArray count];//比全局集合多一个模块
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)cView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ChildCell * cell =  (ChildCell *)[cView dequeueReusableCellWithReuseIdentifier:@"ChildCell" forIndexPath:indexPath];

        NSDictionary *child = [_childArray objectAtIndex:indexPath.row]; //生产一个应用模块
        cell.checkLabel.text = child[@"text"];
    if (indexPath.row!=0) {
        cell.checkLabel.textColor = [UIColor blackColor];
        cell.checkView.backgroundColor = [UIColor whiteColor];
    }
    return cell;
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ChildCell *cell =(ChildCell * ) [collectionView cellForItemAtIndexPath:indexPath];
   
    for (int i=0; i<_childArray.count; i++) {
         NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
         ChildCell *tempcell =(ChildCell * ) [collectionView cellForItemAtIndexPath:tempIndexPath];
         tempcell.checkLabel.textColor = [UIColor blackColor];
        tempcell.checkView.backgroundColor = [UIColor whiteColor];
    }
    cell.checkLabel.textColor = [UIColor whiteColor];
    cell.checkView.backgroundColor = PinkColor;
//    if((long)indexPath.row==[_imagePaths count]){//如果表格的序号 等于image集合的最大长度
//        [self choseButtonClicked];
//    }else{
//        if (cell.image.image!=nil) {
//            [SJAvatarBrowser showImage:cell.image];//调用方法
//        }
//        return;
//    }
//    
}

- (IBAction)sleep{}
- (IBAction)weight{}
- (IBAction)remark{}
@end
